package com.balloon.gateway.security.user.web;

import com.balloon.gateway.redis.RedisUtils;
import com.balloon.gateway.utils.RandomUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;


/**
 * 发送短信
 *
 * @author liaofuxing
 * @date 2019/03/10 4:39
 * @E-mail liaofuxing@outlook.com
 */
@RestController
public class SendSmsController {

    private static final Logger log = LoggerFactory.getLogger(SendSmsController.class);
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping("/sendSms")
    @ResponseBody
    public void sendSms(String phone){
        RedisUtils redisUtils = new RedisUtils(stringRedisTemplate);
        String smsCode = RandomUtils.randomLetterUpperCaseOrNumber(6);
        log.info("发送给【{}】的验证码是{}",phone,smsCode);
        redisUtils.setEx("SYSTEM_USER_SMS_CODE:" + phone, smsCode, 20, TimeUnit.MINUTES);
    }

}
